# -*- coding: utf-8 -*-
"""
    @Author ljy
    @Date 2020/11/4 17:26
    @Describe 
"""

from dbs import _rds

# 默认port=6379,db=1
# decode_responses=True  字节类型变成字符串

# 保存token，建立token和user_id的绑定关系
def save_token(token,user_id):
    _rds.set(token, user_id)

# 根据token获取绑定的user_id
def get_user_id(token):
    return _rds.get(token)

# 验证token是否有效
def has_token(token):
    return _rds.exists(token)

# 思考：海量用户登出时，如何删除token
def remove_token(token):
    if has_token(token):
        _rds.delete(token)

if __name__ == '__main__':
    print(_rds.get('bcef0342eae04bf7924bf8df73a3943b'))